package chapter07

import scala.collection.mutable

/**
 *
 * @author cdhuangchao3
 * @date 2023/6/11 9:11 AM
 */
object Test09_MutableMap {
  def main(args: Array[String]): Unit = {
    // 1.创建map
    val map1 = mutable.Map("a" -> 3, "b" -> 5, "hello" -> 3)
    println(map1)
    println(map1.getClass)

    // 2.添加元素
    map1.put("c", 5)
    map1.put("b", 9)

    map1 += (("d", 9))
    println(map1)
    println("=" * 20)

    // 3.删除元素
    map1.remove("c")

    map1 -= "d"
    println(map1)

    // 4.修改
    map1.update("c", 10)
    map1 += (("a", 9))
    println(map1)
    // 5.合并
    val map2: Map[String, Int] = Map("a" -> 1, "b" -> 3, "hello" -> 4, "e" -> 34)
    val map3 = map2 ++ map1
    println(map3)
    
    map1 ++= map2
    println(map1)

  }
}
